package anno;

import com.alibaba.dubbo.config.*;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableDubbo(scanBasePackages = "anno.service")
public class DubboConfiguration {

    @Bean//application->当前应用名->用作给zookeeper注册中心计算应用间的依赖关系
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("application-name-provider-by-anno");//*
        /*applicationConfig.setOwner("catface");
        applicationConfig.setQosEnable(true);
        applicationConfig.setQosAcceptForeignIp(false);
        applicationConfig.setQosPort(50002);*/
        return applicationConfig;
    }

    /*@Bean
    public MonitorConfig monitorConfig() {
        MonitorConfig monitorConfig = new MonitorConfig();
        monitorConfig.setProtocol("registry");
        return monitorConfig;
    }*/

    @Bean//registry->声明一个注册中心
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        //registryConfig.setAddress("N/A");//不使用zookeeper的话->使用点对点

        registryConfig.setId("registry-id-provider-by-anno");
        //address=zookeeper://localhost:2181
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("localhost");
        //本地服务的端口2181需要和zookeeper中配置的clientPort一致
        registryConfig.setPort(2181);
        return registryConfig;
    }

    @Bean//dubbo的协议配置
    public ProtocolConfig protocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");//webservice/http/hessain/thrift
        //指定dubbo协议的暴露端口为20880->其他应用通过20880端口来调用该dubbo服务
        protocolConfig.setPort(20880);
        return protocolConfig;
    }

    @Bean//dubbo的配置项
    public ProviderConfig providerConfig() {
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setTimeout(5000);
        return providerConfig;
    }
}